home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group93b.txt / 000037_icon-group-sender _Wed Apr 28 13:10:24 1993.msg < prev    next >
Internet Message Format  |  1993-06-16  |  2KB

  1. Received: by cheltenham.cs.arizona.edu; Wed, 28 Apr 1993 07:46:39 MST
  2. Date: Wed, 28 Apr 93 13:10:24 GMT
  3. From: Jerry D. Nowlin <iwtqg!@iwtqg.UUCP:nowlin>
  4. Message-Id: <9304281310.AA23936@iwtqg>
  5. To: @att.UUCP:cs.arizona.edu!icon-group
  6. Subject: Re: Help!
  7. Status: R
  8. Errors-To: icon-group-errors@cs.arizona.edu
  9.  
  10.  > erholm@CS.ColoState.EDU (scott erholm) writes:
  11.  >
  12.  > In Pascal, I could pass values to and from procedures in this manner:
  13.  >
  14.  > Procedure P (VAR x, y, z : Integer; l, m : Real);
  15.  >    (* procedure body *)
  16.  > end;
  17.  >
  18.  > And the call to P would look like this:
  19.  >
  20.  > P (a, b, c, 10, 20);
  21.  >
  22.  > meaning that procedure P would get 10 and 20 for l and m, and would
  23.  > pass the values of x, y, and z back to the calling program.
  24.  
  25. In Icon you can pass a list into a procedure and then stuff things into it
  26. or yank things out of it and when the procedure exits the list remains
  27. modified.  If you pass an empty list to a procedure you can put the x, y
  28. and z values in it and access them from the calling routine.  An empty
  29. table may be more convenient if you want to access the values returned in a
  30. specific order.
  31.  
  32. Finally, while an Icon procedure can only return one item, that item can be
  33. a list or table or any other Icon type.  Rather than including an empty
  34. list or table in the parameter list why not just return one you constructed
  35. on the fly inside the procedure.  Icon magically keeps the values in the
  36. list or table around for you until you don't need them anymore.  Oh sure...
  37. you could explain it in terms of pointers and that other technical stuff
  38. but I like magic.
  39.  
  40.     procedure main()
  41.         addem(l := [],t := table())
  42.         every write(!l | t[1 to 3] | !retem())
  43.     end
  44.  
  45.     procedure addem(l,t)
  46.         every put(l,"new"|"list"|"items")
  47.         t[1] := "and"
  48.         t[2] := "table"
  49.         t[3] := "values"
  50.     end
  51.  
  52.     procedure retem()
  53.         every put(l := [],"and"|"more"|"list"|"items")
  54.         return l
  55.     end
  56.  
  57. Jerry Nowlin
  58. nowlin@iwtqg.att.com (work)
  59. isidev!nowlin@uunet.uu.net (home)
  60.